package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Src;
import org.akomantoso.core.data.group.HTMLMarker;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * The element img is an HTML element and is used in Akoma Ntoso as in HTML, for including an image. It is a marker.
 * 
 * <pre>
 * 	<xsd:element name="img">
 * 		<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="markeropt">
 * 					<xsd:attributeGroup ref="src"/>
 * 					<xsd:attribute name="width" type="xsd:integer"/>
 * 					<xsd:attribute name="height" type="xsd:integer"/>
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 *		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 */
public final class Img extends MarkerOpt implements Src, HTMLMarker {

	public static final String ELEMENT = "img";

	public static final String ATTRIBUTE_WIDTH = "width";
	public static final String ATTRIBUTE_HEIGHT = "height";

	private String _src;
	private String _alt;
	private String _width;
	private String _height;

	public String getSrc() {
		return _src;
	}

	public void setSrc(String src) {
		_src = src;
	}

	public String getAlt() {
		return _alt;
	}

	public void setAlt(String alt) {
		_alt = alt;
	}

	public String getWidth() {
		return _width;
	}

	public void setWidth(String width) {
		_width = width;
	}

	public String getHeight() {
		return _height;
	}

	public void setHeight(String height) {
		_height = height;
	}

	/**
	 * @see org.akomantoso.core.data.MarkerOpt#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeSrc(out, this);
		OutputUtil.writeAttribute(out, ATTRIBUTE_HEIGHT, _height);
		OutputUtil.writeAttribute(out, ATTRIBUTE_WIDTH, _width);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.MarkerOpt#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_src = in.readAttribute(ATTRIBUTE_SRC);
		_alt = in.readAttribute(ATTRIBUTE_ALT);
		_width = in.readAttribute(ATTRIBUTE_WIDTH);
		_height = in.readAttribute(ATTRIBUTE_HEIGHT);
		super.readExternal(in);
	}

	/**
	 * @see ec.ep.visitor.AKVisitable#accept(ec.ep.visitor.AKVisitor)
	 */
	public void accept(AKVisitor visitor) {
		visitor.visit(this);
	}
}